package com.lantu;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

public class codeGen {
    public static void main(String[] args) {
        String url = "jdbc:mysql://42.193.105.220:3306/Scholarship_Db?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "iconroot";
        String autor="mabc";
        String moudleName = "sys";
        String mapperLocation = "G:\\webEnd\\webEnd\\sys\\src\\main\\resources\\mapper\\" + moudleName;
        String tables = "Application,rules,scholarship,score,students,teachers,user";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(autor) // 设置作者
                            .fileOverride()//覆盖已生成文件
                            //.enableSwagger() // 开启 swagger 模式
                            .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder ->
                        builder.parent("com.lantu") // 设置父包名
                                .moduleName(moudleName) // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)) // 设置mapperXml生成路径
                )
                .strategyConfig(builder ->
                        builder.addInclude(tables) // 设置需要生成的表名
                                //.addTablePrefix("s_") // 设置过滤表前缀
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
